package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.telnet.ITelnet;
import com.chinanet.utils.telnet.Socket2Telnet;

import java.net.Socket;
import java.util.Map;
/**
 * ZX_Mmtel_Query_UBEBI_Imp
 * 中兴IMS-mmtel网元-查询用户补充业务
 *
 * @author zyd
 * SHOW OSU SBRSRV:PUI="tel:+8657688910054";
 *
 * 有问题：字符串匹配模板是错的，然后出参的格式是数据表
 */
public class ZX_Mmtel_Query_UBEBI_Imp implements WorkInterFace {

    @Override
    public String getName() {
        return "查询用户补充业务";
    }

    @Override
    public String getDesciption() {
        return "测试方法";
    }

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public Attr[] getInAttrs() {
        Attr[] in = new Attr[1];
        in[0] = new Attr("command", "查询指令", AttrType.TYPE_String, true);
        return in;
    }

    @Override
    public Attr[] getOutAttrs() {
        Attr[] out = new Attr[2];
        out[0] = new Attr("result", "查询结果", AttrType.TYPE_String, true);
        out[1] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
        return out;
    }

    @Override
    public Map<String, Object> init(Map<String, Object> data) {
        String param = ITelnet.getInputPhoneFormat(data.get("command").toString());
        Socket2Telnet s = new Socket2Telnet(new Socket(), "134.96.213.68", 21123);
        s.getIns().add("tz.skb");
        s.getIns().add("tz.skb111");
        s.getIns().add("SET AMO:NAME=\"HZMMTEL202-SSS_141\"");
        s.getIns().add("get");
        s.getIns().add("SHOW OSU SBRSRV:PUI=\""+param+"\"");
        s.setProp("$HZMMTEL202-SSS_141>");
        s.run();
        if (s.getResult() != null) {
            System.out.println("成功获取数据");
        } else {
            System.out.println("发生错误");
        }
        Map<String, Object> outmap;
        String pattern = "\\S+\\s+\\|[\\S+\\s+\\|]+\\S+\\s+\\n";
        // 将结果进行格式化
        String result = s.getResult().toString();
        outmap = ITelnet.matchingTable(pattern, result);
        outmap.put("log",s.getResult().toString());
        return outmap;
    }
}
